package main.java.web.servlet;

import main.java.domain.Task;
import main.java.domain.User;
import main.java.service.ResultService;
import main.java.service.impl.ResultServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/submitTaskServlet")
public class SubmitTaskServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取学生id
        HttpSession session = request.getSession();
        int id = (int) request.getAttribute("id");

        // 获取路径
        String path = (String) request.getAttribute("path");

        // 获取作业id
        Task task = (Task) session.getAttribute("task");
        int taskid = task.getId();

        // 调用service存储学生提交的作业
        ResultServiceImpl service = new ResultServiceImpl();
        service.add(id, taskid, path);

        response.sendRedirect(request.getContextPath()+"/index.jsp");
    }
}
